package http

import (
	"errors"
	"flare-admin/http/handler"
)

func (s *FlareHttpServer) RegisterRoute() error {
	eng := s.engine
	if eng == nil {
		return errors.New("engine is nil")
	}
	debugG := eng.Group("/debug")
	{
		debugG.GET("/hello", Wrapper(handler.HelloWorld))
	}

	// 微服务调用链
	micro := eng.Group("/micro")
	{
		micro.GET("/pattern/all", Wrapper(handler.GetAllPattern))
		micro.POST("/pattern/add", Wrapper(handler.AddPattern))
		micro.GET("pattern/result/all", Wrapper(handler.GetAllPatternMatchResult))
		micro.POST("/pattern/result/add", Wrapper(handler.AddPatternResult))
	}
	// 反弹shell
	reversesh := eng.Group("/reversesh")
	{
		// deprecated
		reversesh.GET("/config/all", Wrapper(handler.GetAllReverseShConfig))
		// deprecated
		reversesh.POST("/config/add", Wrapper(handler.AddReverseConfig))
		// deprecated
		reversesh.POST("/enable", Wrapper(handler.EnableReverseSh))

		reversesh.POST("/uploadRecord", Wrapper(handler.UploadReverseShRecord))
		reversesh.GET("/audit/results", Wrapper(handler.GetAllReverseShAuditResults))
	}

	// 集群
	cluster := eng.Group("/cluster")
	{
		// 总体
		cluster.GET("/all", Wrapper(handler.GetAllCluster))
		cluster.POST("/add", Wrapper(handler.AddClusterConfig))
		cluster.POST("/delete", Wrapper(handler.DeleteClusterConfig))

		// 集群clientset从数据库中捞出来，进入集群视图前一定需要调用该接口
		cluster.POST("/loadconfig/:cluster_id", Wrapper(handler.LoadClusterConfigFromDB))

		// 单个集群
		cluster.GET("/get/:cluster_id", Wrapper(handler.GetClusterMetaInfoByID))
		cluster.GET("resources/:cluster_id", Wrapper(handler.GetClusterResourceByID))
		cluster.GET(":cluster_id/nodes", Wrapper(handler.GetClusterNodesByID))
		cluster.GET(":cluster_id/namespaces", Wrapper(handler.GetClusterNamespacesByID))

		// pod
		pod := cluster.Group("/pod")
		{
			pod.GET("/list/:cluster_id/:namespace", Wrapper(handler.GetAllPodsInNamespace))
			pod.POST("/create/:cluster_id", Wrapper(handler.CreatePodInClusterID))
			pod.POST("/createByYaml", Wrapper(handler.CreatePodByYaml))
			pod.POST("/delete", Wrapper(handler.DeletePodInClusterID))
		}

		//deployment
		deployment := cluster.Group("/deployment")
		{
			deployment.GET("/list/:cluster_id/:namespace", Wrapper(handler.GetAllDeploymentsInNamespace))
			deployment.POST("/createByYaml", Wrapper(handler.CreateDeploymentByYaml))
			deployment.POST("/delete", Wrapper(handler.DeleteDeploymentInClusterID))
		}

		// 延迟查询
		latency := cluster.Group("/latency")
		{
			latency.GET("/all/:cluster_id", Wrapper(handler.GetRangedLatencyInfoIn))
			latency.GET("/pair/:cluster_id", Wrapper(handler.GetRangedLatencyInfoPair))
		}

		// 调度相关
		scheduling := cluster.Group("/scheduling")
		{
			scheduling.POST("/addRecord/:cluster_id", Wrapper(handler.AddPodGroupSchedulingRecord))
			scheduling.POST("/updateRecord/:cluster_id", Wrapper(handler.UpdatePodGroupSchedulingRecord))
			scheduling.POST("/updateRecordStatus/:cluster_id", Wrapper(handler.UpdateSchedulingRecordStatus))

			scheduling.GET("/getRecords/:cluster_id", Wrapper(handler.GetAllPodGroupSchedulingRecords))
			scheduling.GET("/getRecord/:cluster_id/:namespace/:name/:uid", Wrapper(handler.GetPodGroupSchedulingRecord))
		}

	}
	// DDoS攻击
	ddos := eng.Group("/ddos")
	{
		ddos.GET("/allflow", Wrapper(handler.GetAllDDoSFlows))
		ddos.GET("/simulate-attack", Wrapper(handler.SimulateAttack))

		// DDoS流量数据管理
		ddos.POST("/flow/add", Wrapper(handler.AddDDoSFlow))
		ddos.POST("/flow/batch-add", Wrapper(handler.AddDDoSFlowsBatch))
		ddos.GET("/flow/by-type", Wrapper(handler.GetDDoSFlowsByType))
		ddos.GET("/flow/by-ip", Wrapper(handler.GetDDoSFlowsByIP))
		ddos.POST("/flow/init", Wrapper(handler.InitializeDDoSFlowsData))
		ddos.GET("/sync/status", Wrapper(handler.GetDDoSFlowSyncStatus))
	}
	// 零信任引擎
	ztrust := eng.Group("/ztrust")
	{
		ztrust.GET("/events", Wrapper(handler.GetAllZtrustEvents))
		ztrust.GET("/events/:cybertwin_id", Wrapper(handler.GetCtZtrustEvents))
		ztrust.GET("/scores", Wrapper(handler.GetAllZtrustScores))
		ztrust.GET("/access-events", Wrapper(handler.GetAllZtrustAccessEvents))
	}
	return nil
}
